#include "VariableEvent.h"
#include <stdexcept>

VariableEvent::VariableEvent(Trigger* trigger, CLimitOp limitOp, double doubleValue)
    : trigger(trigger), limitOp(limitOp), doubleValue(doubleValue) {}

Trigger* VariableEvent::getTrigger() {
    return this->trigger;
}

CLimitOp VariableEvent::getLimitOp() {
    return this->limitOp;
}

double VariableEvent::getDoubleValue() {
    return this->doubleValue;
}

bool VariableEvent::isMatching(double realValue) {
    switch (this->limitOp) {
    case CLimitOp::LESS_THAN:
        return realValue < this->doubleValue;
    case CLimitOp::LESS_THAN_OR_EQUAL:
        return realValue <= this->doubleValue;
    case CLimitOp::EQUAL:
        return realValue == this->doubleValue; // TODO probably bad, probably needs epsilon comparison
    case CLimitOp::GREATER_THAN:
        return realValue > this->doubleValue;
    case CLimitOp::GREATER_THAN_OR_EQUAL:
        return realValue >= this->doubleValue;
    case CLimitOp::NOT_EQUAL:
        return realValue != this->doubleValue;
    }
    throw std::invalid_argument("Invalid limit op");
}

void VariableEvent::fire(GlobalScope& globalScope) {
    //TriggerExecutionScope triggerScope(this->trigger);
    //globalScope.queueTrigger(nullptr, nullptr, this->trigger, &triggerScope, &triggerScope);
}